import Vue from "vue";
import Router from "vue-router";
import Home from "./views/Home.vue";
import store from "./store";

Vue.use(Router);

const router = new Router({
  linkExactActiveClass: "active",
  linkActiveClass: "active",
  // mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    {
      path: "/",
      name: "home",
      component: Home
    },
    {
      path: "/account/bind",
      name: "accountBind",
      meta: {
        title: "绑定手机"
      },
      component: () =>
        import(/* webpackChunkName: "game" */ "./views/account/Bind.vue")
    },
    {
      path: "/account/unbind",
      name: "settingUnbind",
      meta: {
        title: "更换手机号"
      },
      component: () =>
        import(/* webpackChunkName: "game" */ "./views/account/UnBind.vue")
    },
    {
      path: "/account/modify",
      name: "settingModify",
      meta: {
        title: "修改密码"
      },
      component: () =>
        import(/* webpackChunkName: "game" */ "./views/account/Modify.vue")
    },
    {
      path: "/user",
      name: "user",
      meta: {
        auth: true,
        title: "个人中心"
      },
      component: () =>
        import(/* webpackChunkName: "game" */ "./views/user/Index")
    },
    {
      path: "/user/setting",
      name: "setting",
      meta: {
        title: "账号中心"
      },
      component: () =>
        import(/* webpackChunkName: "game" */ "./views/user/Setting.vue")
    },
    {
      path: "/user/news",
      name: "news",
      meta: {
        title: "我的消息"
      },
      component: () =>
        import(/* webpackChunkName: "game" */ "./views/user/News.vue")
    },
    {
      path: "/user/log",
      name: "log",
      meta: {
        title: "账户明细"
      },
      component: () =>
        import(/* webpackChunkName: "game" */ "./views/user/Log.vue")
    },
    {
      path: "/user/gift",
      name: "userGift",
      meta: {
        title: "gift_name"
      },
      component: () =>
        import(/* webpackChunkName: "game" */ "./views/user/Gift.vue")
    },
    {
      path: "/user/contact",
      name: "contact",
      meta: {
        title: "联系客服"
      },
      component: () =>
        import(/* webpackChunkName: "game" */ "./views/user/Contact.vue")
    },
    {
      path: "/game",
      name: "gameDetail",
      meta: {
        title: "游戏详情"
      },
      component: () =>
        import(/* webpackChunkName: "game" */ "./views/game/Detail")
    },
    {
      path: "/list",
      name: "gameList",
      meta: {
        title: "游戏列表"
      },
      component: () =>
        import(/* webpackChunkName: "game" */ "./views/game/List")
    },
    {
      path: "/server",
      name: "gameServer",
      meta: {
        // title: '开服'
      },
      component: () =>
        import(/* webpackChunkName: "game" */ "./views/game/Server")
    },
    {
      path: "/gift",
      name: "gift",
      meta: {
        // title: '礼包'
      },
      component: () =>
        import(/* webpackChunkName: "game" */ "./views/gift/Index")
    },
    {
      path: "/gift/:id",
      name: "giftDetail",
      meta: {
        title: "礼包详情"
      },
      component: () =>
        import(/* webpackChunkName: "game" */ "./views/gift/Detail")
    },
    {
      path: "/seo/index",
      name: "seo",
      meta: {
        title: "seo落地页"
      },
      component: () =>
        import(/* webpackChunkName: "game" */ "./views/seo/Index")
    },
    {
      path: "/advertisement/xiaokr",
      name: "ad_xiaokr",
      meta: {
        title: "小氪手游"
      },
      component: () =>
        import(/* webpackChunkName: "game" */ "./views/advertisement/Xiaokr")
    },
    {
      path: "/advertisement/private_policy",
      name: "ad_private_policyr",
      meta: {
        title: "隐私协议"
      },
      component: () =>
        import(/* webpackChunkName: "game" */ "./views/advertisement/PrivatePolicy")
    },
    {
      path: "/advertisement/user_permission",
      name: "ad_user_permission",
      meta: {
        title: "用户权限"
      },
      component: () =>
        import(/* webpackChunkName: "game" */ "./views/advertisement/UserPermission")
    }
  ]
});

router.afterEach((to, from) => {
  if (document.documentElement.scrollTop) {
    document.documentElement.scrollTop = 0;
  } else if (document.body.scrollTop) {
    document.body.scrollTop = 0;
  }

  if (to.meta.auth) {
    if (!store.state.userinfo.mem_id) {
      /* global HuoSdk */
      // HuoSdk.login()
    }
  } else {
    /* global HuoUtils */
    HuoUtils.switchTemplate();
  }
});
export default router;
